import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
import index from "../views/index.vue";
import goods from "@/views/page/Goods.vue";
import goodsDetail from "../views/page/GoodsDetail.vue";
import register from "../views/user/Register.vue";
import login from "../views/user/Login.vue";
import changePassword from "@/views/user/changePassword.vue";
import shopping from "@/views/shopping/Shopping.vue";
import transport from "@/views/shopping/Transport.vue";
import store from "@/views/page/Store.vue";
import designerDetails from "@/views/category/DesignerDetails.vue"
import buildingMaterial from "@/views/category/BuildingMaterial.vue";
import appliance from "@/views/category/appliance";
import furniture from "@/views/category/Furniture.vue"
import brand from "@/views/category/Brand.vue";
import payment from "@/views/shopping/Payment.vue";
import personalDetails from "@/views/user/PersonalDetails.vue";
import introduce from "@/views/shop/Introduce.vue";
import floors from "@/views/category/Floors.vue";
import myorder from "@/views/user/MyOrder.vue";
import integ from "@/views/user/integ.vue"
import accountInformation from "@/views/user/AccountInformation.vue";
import paymentSuccessful from "@/views/shopping/PaymentSuccessful.vue";
import orderDetails from "@/views/user/orderDetails.vue";
import orderEvaluation from "@/views/user/OrderEvaluation.vue";
import ASProgress from "@/views/user/ASProgress.vue";
import search from "@/views/page/Search.vue";
import pointsExchange from "@/views/pointsMall/PointsExchange.vue";
import integralGoods from "@/views/pointsMall/IntegralGoods.vue";
import record from "@/views/pointsMall/Record.vue";
import addressManagement from "@/views/user/AddressManagement.vue";
import createOrder from "@/views/pointsMall/CreateOrder.vue";
import pointsPayment from "@/views/pointsMall/PointsPayment.vue";
import exchangeOrderDetails from "@/views/pointsMall/ExchangeOrderDetails.vue";
import pointsOrder from "@/views/pointsMall/pointsOrder.vue";


import i18n from "@/i18n";

import { Message } from 'element-ui';
import Cookie from '@/util/Cookie';
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    name: "login",
    component: login,
    meta: {
      title: "登录"
    }
  },
  {
    path: "/register",
    name: "register",
    component: register,
    meta: {
      title: "注册"
    }
  },
  {
    path: "/changePassword",
    name: "changePassword",
    component: changePassword,
    meta: {
      title: "修改密码"
    },
  },
  {
    path: "/personalDetails",
    name: "personalDetails",
    component: personalDetails,
    meta: {
      title: "个人信息"
    },
  },
  {
    path: "/shopping",
    name: "shopping",
    component: shopping,
    meta: {
      title: "购物车"
    },
    beforeEnter:(to, from, next)=>{
      if(Cookie.getCookie('token') != undefined) {
        next()
      } else {
        Message({
          showClose: true,
          message: i18n.t("share.Message.login"),
          type: "error"
        });
        document.title = from.meta.title; //把标题变成来的页面标题，不然会变成拦截页面的标题
        next(from.path)
      }
    }
  },
  {
    path: "/transport",
    name: "transport",
    meta: {
      title: "填写订单信息"
    },
    component: transport,
    beforeEnter:(to, from, next)=>{
      // 判断token,是否登陆
      if(Cookie.getCookie('token') != undefined) {
        next()
      } else {
        // 没有token，没有登陆
        Message({
          showClose: false,
          message: i18n.t("share.Message.login"),
          type: "error"
        });
        // 跳到主页
        next('/')
      }
    }
  },
  {
    path: "/payment",
    name: "payment",
    component: payment,
    meta: {
      title: "付款"
    }
  },
  {
    path: "/store",
    name: "store",
    component: store,
    meta: {
      title: "门店"
    }
  },
  {
    path: "/introduce",
    name: "introduce",
    component: introduce,
    meta: {
      title: "门店介绍"
    }
  },
  {
    path: "/designerDetails",
    name: "designerDetails",
    component: designerDetails,
  },
  {
    path: "/buildingMaterial",
    name: "buildingMaterial",
    component: buildingMaterial,
    meta: {
      title: "建材"
    }
  },
  {
    path: "/furniture",
    name: "furniture",
    component: furniture,
    meta: {
      title: "家具"
    }
  },
  {
    path: "/appliance",
    name: "appliance",
    component: appliance,
    meta: {
      title: "家电"
    }
  },
  {
    path: "/brand",
    name: "brand",
    component: brand,
    meta: {
      title: "设计师"
    }
  },
  {
    path: "/floors",
    name: "floors",
    component: floors,
    meta: {
      title: "楼盘"
    }
  },
  {
    path: "/paymentSuccessful",
    name: "paymentSuccessful",
    component: paymentSuccessful,
    meta: {
      title: "付款成功"
    }
  },
  {
    path:'/pointsExchange',
    name:'pointsExchange',
    component:pointsExchange,
    meta: {
      title: "积分兑换"
    },
  },
  {
    path: '/integralGoods',
    name: 'integralGoods',
    component: integralGoods,
    meta: {
      title: "积分商品详情"
    },
  },
  {
    path: '/record',
    name: 'record',
    component: record,
    meta: {
      title: "参与记录"
    },
  },
  {
    path: '/createOrder',
    name: 'createOrder',
    component: createOrder,
    meta: {
      title: "创建订单"
    },
  },
  {
    path: '/pointsPayment',
    name: 'pointsPayment',
    component: pointsPayment,
    meta: {
      title: "收银台"
    },
  },
  {
    path:'/accountInformation',
    name:'accountInformation',
    component:accountInformation,
    children: [
      {
        path:'myorder',
        name:'myorder',
        component:myorder,
        meta: {
          title: "我的订单"
        },
      },
      {
        path:'orderDetails',
        name:'orderDetails',
        component:orderDetails,
        meta: {
          title: "订单详情"
        },
      },
      {
        path:'orderEvaluation',
        name:'orderEvaluation',
        component:orderEvaluation,
        meta: {
          title: "评价"
        },
      },
      {
        path:'ASProgress',
        name:'ASProgress',
        component:ASProgress,
        meta: {
          title: "售后申请"
        },
      },
      {
        path:'addressManagement',
        name:'addressManagement',
        component:addressManagement,
        meta: {
          title: "收货地址管理"
        },
      },
      {
        path: 'exchangeOrderDetails',
        name: 'exchangeOrderDetails',
        component: exchangeOrderDetails,
        meta: {
          title: "订单详情"
        },
      },
      {
        path: "pointsOrder",
        name: "pointsOrder",
        component: pointsOrder,
        meta: {
          title: "我的积分订单"
        },
      },
      
    ]
  },
  {
    path:"/integ",
    name:"integ",
    component:integ,
    meta:{
      title:"个人积分"
    }
  },
  
  {
    path: "/",
    name: "Home",
    component: Home,
    children:[
      {
        path:'/',
        name:'index',
        component:index,
        meta: {
          title: "广州优粤家"
        }
      },
      {
        path:'goods',
        name:'goods',
        component:goods,
        meta: {
          title: "商品列表"
        },
      },
      {
        path:'goodsDetail',
        name:'goodsDetail',
        component:goodsDetail,
        meta: {
          title: "商品详情"
        },
      },
      {
        path:'search',
        name:'search',
        component:search,
        meta: {
          title: "商品列表"
        },
      },
    ]
  },
];

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes,
  scrollBehavior () {
    // return 期望滚动到哪个的位置
    return { x: 0, y: 0 }
  }
});


export default router;
